<template>
	<view>
		<uni-drawer id="drawer" :visible="drawFlag" :mask="true" mode="bottom" @close="closeDrawer" width="100%" height="60%" radiusTop="20upx">
			<view class="coupon couponColor">
				<view class="coupon-top">
					<text>优惠券</text>
					<i class="icon erricon" @tap="closeDrawer">&#xe698;</i>
					<!-- <image mode="widthFix" src="../../static/image/index/add_images/integral_01.png" @tap="closeDrawer"></image> -->
				</view>
				<scroll-view class="coupon-con" scroll-y :style="{height:searchHeight+'px'}">
					<view class="coupon-cat" v-for="(item,index) in couponList" :key="index">
						<view class="coupon-list" :class="item.use_state ? 'coupon-list_pass' : ''">
							<view class="coupon-list_left">
								<view class="coupon-list_leftFont">
									<text class="one">{{item.price}}</text>
									<text class="two">{{item.satisfy_name}}</text>
									<!-- <text class="two" v-else>无门槛</text> -->
								</view>
							</view>
							<text class="coupon-text"></text>
							<view class="coupon-list_right">
								<view class="coupon-list_rightImg">
									<text>{{item.name}}</text>
									<view v-if="item.use_state">
										<image v-if="item.check" @tap.stop="$emit('select',index)" :src="Url+'add_images/sc-success.png'" mode="widthFix"></image>
										<image v-else @tap.stop="$emit('select',index)" :src="Url+'add_images/sc-pass.png'" mode="widthFix"></image>
									</view>
								</view>
								<text class="coupon-list_righttext" v-if="item.expire_type == 2">领取后{{item.expire_day}}天内有效</text>
								<text class="coupon-list_righttext" v-else>{{item.start_time}}至{{item.end_time}}</text>
								<view class="coupon-list_rightTitle">
									<view class="coupon-list_rightTitle-left" @tap.stop="$emit('Tips',index)">
										<text>使用说明</text>
										<image v-if="!item.tipsShow" :src="Url+'add_images/more-down.png'" mode="widthFix"></image>
										<image v-else :src="Url+'add_images/more-up.png'" mode="widthFix"></image>
									</view>
									<view class="coupon-list_rightTitle-btn" v-if="!item.use_state" @tap="$emit('draw',index,item)">立即领取</view>
								</view>
							</view>
						</view>
						<!-- 隐藏 -->
						<view class="coupon-hide" v-if="item.tipsShow">
							<p v-if="item.memo"> {{item.memo}}</p>
							<p v-if="item.text"> {{item.text}}</p>
						</view>
					</view>
				</scroll-view>
			</view>
		</uni-drawer>
	</view>
</template>

<script>
	import uniDrawer from '@/components/uni-drawer/uni-drawer.vue'
	export default {
		components:{
			uniDrawer
		},
		props:{
			drawFlag:{
				type:Boolean,
				default:true
			},
			hideHeight:{
				type:Number
			},
			couponList:{
				type:Array
			}
		},
		watch:{
			drawFlag(old,value){
				if(old){
					this.heightConpun()
				}
			}
		},
		data() {
			return {
				Url:this.Imgurl,
				// list:[
				// 	{price:'30',title:'新人优惠券',check:true,pass:false,tipsShow:false},
				// 	{price:'40',title:'新人优惠券1',check:false,pass:true,tipsShow:false},
				// 	{price:'50',title:'新人优惠券2',check:false,pass:false,tipsShow:false},
				// 	{price:'60',title:'新人优惠券3',check:false,pass:true,tipsShow:false}
				// ],
				searchHeight:0
			};
		},
		methods:{
			heightConpun(){
				let that = this;
				var parent = 0;
				let version = uni.getSystemInfoSync().version
				that.$nextTick(function(){
					if(!version){
					   const query1 = uni.createSelectorQuery()
					   query1.select('.coupon-top').boundingClientRect(data => {
						   // console.log('触发',data)
					   	that.searchHeight = that.hideHeight - data.height;
					   }).exec();	
					}else{
						var observer1 = uni.createIntersectionObserver(this);
						observer1.relativeTo('.coupon').observe('.coupon-top', (res) => {
						   // console.log('observer1',res)
						   let height1 = res.boundingClientRect.height;
						   that.searchHeight = that.hideHeight - height1;
						})
					}
				})
			},
			closeDrawer(){
				this.$emit("close")
			}
		}
	}
</script>

<style lang="scss">

	.icon{
		font-size:32upx;
		color: #999999;
	}
	.coupon{
		width: 100%;
		&-con{
			padding:40upx 30upx 0 30upx;
			box-sizing: border-box;
		}
		&-cat{
			position:relative;
			margin-bottom: 20upx;
		}
		&-list_rightTitle-btn{
			padding: 8upx 33upx;
			background:linear-gradient(90deg,rgba(253,115,119,1),rgba(255,39,65,1));
			color: #FFFFFF;
			font-size: 24upx;
			border-radius:40upx;
		}
		&-hide{
			width: 100%;
			padding: 27upx 0 27upx 41upx;
			background-color: #FFFDFD;
			box-sizing: border-box;
			p{
				font-size: 20upx;
				color: #656565;
				display: flex;
				align-items: center;
				margin-bottom: 10upx;
				&::before{
					content: "";
					display: inline-block;
					width: 5upx;
					height: 5upx;
					border-radius: 50%;
					background-color: #333333;
					margin-right: 10upx;
				}
			}
		}
		&-list{
			width: 100%;
			background-color: #FFFBFB;
			display: flex;
			align-items: center;
			padding: 30upx 22upx 27upx 0;
			border-radius: 10upx;
			box-sizing: border-box;
			position: relative;
			max-height: 200upx;
			&::before{
				position: absolute;
				top: 0;
				left: 0;
				height: 100%;
				width: 12px;
				content: "";
				display: block;
				background: url(https://jy-shops.oss-cn-beijing.aliyuncs.com/client/image/add_images/sc-couL.png);
				background-size: contain;
				background-repeat: no-repeat;
			}
		}
		&-list_pass{
			&::after{
				position: absolute;
				right: 0;
				bottom: 0;
				content: "";
				display: block;
				width: 85upx;
				height: 79upx;
				background: url(https://jy-shops.oss-cn-beijing.aliyuncs.com/client/image/add_images/sc-couicon.png);
				background-repeat: no-repeat;
				background-size: cover;
			}
		}
		&-list_rightTitle{
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		&-list_righttext{
			font-size: 20upx;
			display: block;
			color: #999999;
			height:45upx;
			overflow: hidden;
		}
		&-list_rightTitle-left{
			display: flex;
			align-items: center;
			text{
				display: block;
				font-size: 20upx;
				color: #999999;
				margin-right: 10upx;
			}
			image{
				width: 22upx;
				height: 12upx;
			}
		}
		&-list_rightImg{
			display: flex;
			align-items: flex-start;
			justify-content: space-between;
			text{
				font-size: 26upx;
				color: #333333;
				display: block;
				height:70upx;
				line-height: 35upx;
				width:300upx;
				overflow: hidden;
			}
			image{
				width: 36upx;
				height: 36upx;
				display: block;
			}
		}
		&-text{
			height: 100%;
			width: 2%;
			border-right: 2upx dashed #F0EEEE;
			display: block;
			position: absolute;
			left: 32%;
			&::after{
				content: "";
				display: block;
				width: 40upx;
				height: 40upx;
				border-radius: 50%;
				background-color: #FFFFFF;
				position: absolute;
				top: -10px;
				left: -37.5%;
			}
			&::before{
				content: "";
				display: block;
				width: 40upx;
				height: 40upx;
				border-radius: 50%;
				background-color: #FFFFFF;
				position: absolute;
				bottom: -10px;
				left: -37.5%;
			}
		}
		&-list_left{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 35%;
			height: 100%;
			.one{
				font-size: 60upx;
				color: #FF2842;
				font-weight: bold;
				display: block;
				text-align: center;
				&::before{
					content: "￥";
					font-size: 48upx;
				}
			}
			.two{
				font-size: 22upx;
				color: #FF2842;
				margin-top: 33upx;
				display: block;
				text-align: center;
			}
		}
		&-list_right{
			padding-left: 5%;
			width: 64%;
		}
	}
	.coupon-top{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding:40upx 30upx;
		box-sizing: border-box;
		text{
			font-size: 28upx;
			color: #333333;
		}
		image{
			width: 28upx;
			height: 28upx;
		}
	}
</style>
